home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / fly8111-.000 / fly8111- / fly8 / shapes / acm2fvx.awk < prev    next >
Text File  |  1979-12-31  |  2KB  |  90 lines

  1. # --------------------------------- acm2fvx.awk ------------------------------
  2.  
  3. #
  4. # This is part of the flight simulator 'fly8'.
  5. # Author: Eyal Lebedinsky (eyal@ise.canberra.edu.au).
  6. #
  7.  
  8. #
  9. # Convert an acm object description into the fly8 .fvx format. To use the
  10. # result, e.g. f16.acm, just rename it to plane.vxx and do a make. This will
  11. # generate the plane.vxx which is loaded at execution time.
  12. #
  13.  
  14. BEGIN    {
  15.     name = ARGV[1]
  16.     acm = name ".acm"
  17.     fly8 = name ".c"
  18.  
  19.     if (getline <acm <= 0) {
  20.         print "could not read line 1 in " name
  21.         exit 1
  22.     }
  23.     objname = $0
  24.  
  25.     if (getline <acm <= 0) {
  26.         print "could not read line 2 in " name
  27.         exit 1
  28.     }
  29.     npoints = $1+0
  30.     npolys  = $2+0
  31.  
  32.     for (i = 1; i <= npoints; ++i) {
  33.         if (getline <acm <= 0) {
  34.             print "input error: point"
  35.             exit 1
  36.         }
  37.         if ($1+0 != i) {
  38.             print "input error: point number"
  39.             exit 1
  40.         }
  41.         points[i,0] = round($3/3*16)    # x
  42.         points[i,1] = round($2/3*16)    # y
  43.         points[i,2] = round(-$4/3*16)    # z
  44.     }
  45.  
  46.     printf ("#include \"shape.h\"\n") >fly8
  47.     printf ("static VERTEX acm_%s[] = {\n", name) >>fly8
  48.  
  49.     for (i = 1; i <= npolys; ++i) {
  50.         if (getline <acm <= 0) {
  51.             print "input error: poly"
  52.             exit 1
  53.         }
  54.         color = $1+0
  55.         nedges = $2+0
  56.         prev = 0;
  57.         outpoint(prev, $3+0, 1)
  58.         for (j = 1; j < nedges; ++j) {
  59.             outpoint(prev, $(j+3), 0)
  60.             prev = $(j+3)
  61.         }
  62.         outpoint(prev, $3+0, 0)
  63.         printf ("\n") >>fly8
  64.     }
  65.     printf ("\t{{0, 0, 0}, V_EOF}\n};\n") >>fly8
  66.  
  67.     close (acm)
  68.     close (fly8)
  69. }
  70.  
  71. function outpoint(prev, p, type) {
  72.     if (type)
  73.         mode = "V_MOVE"
  74.     else if ((prev, p) in edge || (p, prev) in edge)
  75.         mode = "V_DUP"
  76.     else {
  77.         mode = "V_DRAW"
  78.         edge[prev, p] = 1
  79.     }
  80.     printf ("\t{{%d, %d, %d}, %s},\n", \
  81.         points[p,0], points[p,1], points[p,2], mode) >>fly8
  82. }
  83.  
  84. function round(f) {
  85.     if (f <= 0)
  86.         return int(f-0.5)
  87.     else
  88.         return int(f+0.5)
  89. }
  90.